package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.entity.NoDisturbReply;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeNoDisturb implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,V4,CLASS,123831,1,040008001121314151070,6173914,A,2250.2255,N,11391.6023,E,0.31,0,020621,FFFFDFFF*/
        //解密
        String[] split = parseCommand(originalData);
        String commandNumber = split[4];    // 指令序列号
        String imei = split[1];   // imei号
        String sequence = split[5];
        String deviceTime = split[7];
        String value = split[6];
        String lat = split[9];
        String lgt = split[11];
        String speed = split[13];
        String orientation = split[14];
        String date = split[15];
        String deviceStatus = split[16];
        List<Double> list = LocationUtils.transiformLatAndLng(lgt, lat);
        NoDisturbReply noDisturbReply = new NoDisturbReply();
        noDisturbReply.setCommandNumber(commandNumber);
        noDisturbReply.setDeviceDate(date);
        noDisturbReply.setDeviceStatus(deviceStatus);
        noDisturbReply.setDeviceTime(deviceTime);
        noDisturbReply.setImei(imei);
        noDisturbReply.setSequence(Integer.parseInt(sequence));
        noDisturbReply.setValue(value);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        noDisturbReply.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_SET_NO_DISTURB,false,"",noDisturbReply);
    }
}
